<template>
  <demoBlock title="异步关闭" padding>
    <vcu-cell is-link title="异步关闭" @click="onClickAsync" />
  </demoBlock>
</template>

<script>
import { defineComponent, ref } from "vue";
import { Dialog } from "../../../components";
export default defineComponent({
  setup() {
    const beforeClose = (action) =>
      new Promise((resolve) => {
        setTimeout(() => {
          if (action === "confirm") {
            resolve(true);
          } else {
            // 拦截取消操作
            resolve(false);
          }
        }, 1000);
      });
    const onClickAsync = () => {
      Dialog.confirm({
        title: "提示",
        message:
          "JavaScript是函数式语言，函数可以实现类，类就是面向对象编程中最基本的概念",
        beforeClose,
      }).then((action) => {
        console.info(action);
      });
    };

    return { onClickAsync };
  },
});
</script>
